package com.shelpe.services.tenant.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shelpe.services.tenant.dao.UsersMapper;
import com.shelpe.services.tenant.model.Users;
import com.shelpe.services.tenant.model.UsersExample;
import com.shelpe.services.tenant.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UsersMapper userMapper;
	
	@Override
	public List<Users> getUserByNick(String nick) {
		// TODO Auto-generated method stub
		UsersExample example = new UsersExample();
		example.createCriteria().andNickEqualTo(nick);	
		List<Users> users = userMapper.selectByExample(example);

		return users;
	}
    
    @Override
    public Long getUserIdByNick(String nick){
        
        List<Users> list = getUserByNick(nick);
        
        if(list != null && list.size()>0){
            return list.iterator().next().getUserId();
        }
        
        return null;
    }
    
    @Override
    public Users getUserByUserId(long userId){
        
        return userMapper.selectByPrimaryKey(userId);
    }
    
    @Override
    public String getNickByUserId(long userId){
        
        Users user = userMapper.selectByPrimaryKey(userId);
        if(user != null){
            return user.getNick();
        }
        
        return null;
    }
	
	@Override
	public List<Users> getAllUsers(){
		UsersExample example = new UsersExample();
		example.createCriteria();
		List<Users> users = userMapper.selectByExample(example);
		
		return users;
	}
	
}
